package cn.edu.ujn.springboot.controller;

import cn.edu.ujn.dao.CarparkInfo;
import cn.edu.ujn.dao.CarparkInfoMapper;
import cn.edu.ujn.service.ICarparkInfoService;
import org.springframework.aop.scope.ScopedProxyUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
public class CarparkInfoController {

    @Autowired
    private ICarparkInfoService carparkInfoService;

    @Autowired
    private CarparkInfoMapper carparkInfoMapper;

    @GetMapping("/carparkinfo")
    public List<CarparkInfo> getList(CarparkInfo carpark) {
        System.out.println("wwwwwwwwwwwwwwwwwwwwwww"+carparkInfoService.selectAll(carpark));
        return carparkInfoService.selectAll(carpark);
    }

//    @GetMapping("/carparkinfo/{num}")
//    public List<Integer> getCarparkId(@PathVariable("num") int num) {
//        return carparkInfoService.selectPrimaryKeys();
//    }

    @PostMapping("/carparkinfo")
    public String addCarparkInfo(@RequestBody CarparkInfo carpark) {
        return carparkInfoService.insert(carpark)== 1 ? "success" : "fail";
    }

    @GetMapping("/carparkinfo/{id}")
    public CarparkInfo getCarparkInfoById(@PathVariable("id") Integer id) {
        System.out.println("iiiiiiiiiiiiiiiiid"+id);
        System.out.println("fanhui"+carparkInfoMapper.selectByPrimaryKey(id));
        return carparkInfoMapper.selectByPrimaryKey(id);
    }

    @PutMapping("/carparkinfo")
    public String updateCarparkInfo(@RequestBody CarparkInfo carpark) {
        return carparkInfoService.updateByPrimaryKeySelective(carpark) == 1 ? "success" : "fail";
    }

    @DeleteMapping("/carparkinfo/{id}")
    public String deleteCarpark(@PathVariable Integer id){
        return carparkInfoService.deleteByPrimaryKey(id) == 1 ? "success" : "fail";
    }


}
